/*     */ package com.ai.core.util;
/*     */
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.PrintStream;
/*     */ import java.io.StringWriter;
/*     */ import org.dom4j.Document;
/*     */ import org.dom4j.DocumentHelper;
/*     */ import org.dom4j.Element;
/*     */ import org.dom4j.io.OutputFormat;
/*     */ import org.dom4j.io.SAXReader;
/*     */ import org.dom4j.io.XMLWriter;
/*     */
/*     */ public class XmlUtil
/*     */ {
/*     */   public static Element parseXml(InputStream in)
/*     */     throws Exception
/*     */   {
/*  25 */     SAXReader saxReader = new SAXReader();
/*  26 */     Document document = saxReader.read(in);
/*  27 */     return document.getRootElement();
/*     */   }
/*     */
/*     */   public static Element parseXmlGBK(InputStream in)
/*     */     throws Exception
/*     */   {
/*  37 */     SAXReader saxReader = new SAXReader();
/*  38 */     InputStreamReader utf8In = new InputStreamReader(in, "gbk");
/*  39 */     Document document = saxReader.read(utf8In);
/*  40 */     return document.getRootElement();
/*     */   }
/*     */
/*     */   public static Element parseXmlOfString(String str)
/*     */     throws Exception
/*     */   {
/*  50 */     ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes());
/*  51 */     Element result = parseXml(in);
/*  52 */     in.close();
/*  53 */     return result;
/*     */   }
/*     */
/*     */   public static Element createElement(String name, String text)
/*     */   {
/*  63 */     Element e = DocumentHelper.createElement(name);
/*  64 */     if ((text != null) && (!(text.trim().equals(""))))
/*  65 */       e.setText(text);
/*  66 */     return e;
/*     */   }
/*     */
/*     */   public static String formatElement(Element e)
/*     */   {
/*  75 */     StringWriter s = new StringWriter();
/*  76 */     OutputFormat format = OutputFormat.createPrettyPrint();
/*  77 */     XMLWriter writer = new XMLWriter(s, format);
/*     */     try {
/*  79 */       writer.write(e);
/*  80 */       writer.close();
/*     */     }
/*     */     catch (IOException ex) {
/*  83 */       ex.printStackTrace();
/*     */     }
/*  85 */     return s.getBuffer().toString();
/*     */   }
/*     */
/*     */   public static void main(String[] args) throws Exception {
/*  89 */     String xml = "<root><item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> <item name = \"qh\" value =\"qh\"/> </root>";
/*     */
/* 100 */     long s = System.currentTimeMillis();
/*     */     Element e;
/* 101 */     for (int i = 0; i < 10000; ++i) {
/* 102 */       e = DocumentHelper.parseText(xml).getRootElement();
/*     */     }
/*     */
/* 106 */     System.out.println("shijian:" + (System.currentTimeMillis() - s));
/* 107 */     s = System.currentTimeMillis();
/* 108 */     for (int i = 0; i < 10000; ++i) {
/* 109 */       e = parseXmlOfString(xml);
/*     */     }
/*     */
/* 113 */     System.out.println("shijian:" + (System.currentTimeMillis() - s));
/*     */   }
/*     */ }

/* Location:           C:\MyEclipse\workspace\boss-inter\lib\simple_http.jar
 * Qualified Name:     com.asiainfo.appframe.ext.exeframe.simplehttp.util.XmlUtil
 * JD-Core Version:    0.5.3
 */